package com.ai.service;

import com.ai.bo.InterviewRecordBO;
import com.ai.mapper.InterviewRecordMapper;
import com.ai.service.impl.InterviewRecordServiceImpl;
import com.ai.service.impl.InterviewerServiceImpl;
import com.ai.vo.InterviewRecordVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Service;
import wst.ai.pojo.interviewrecord.InterviewRecord;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class InterviewRecordService implements InterviewRecordServiceImpl {
    @Autowired
    private InterviewRecordMapper interviewRecordMapper;
    @Override
    public boolean isCandidateRecordExit(String candidateId) {
        InterviewRecord interviewRecord = interviewRecordMapper.selectOne(new QueryWrapper<InterviewRecord>().eq("candidate_id", candidateId));
        if (interviewRecord == null){
            return false;
        }else {
            //        上次面试时间
            LocalDateTime updatedTime = interviewRecord.getUpdatedTime();
//        当前时间
            LocalDateTime now = LocalDateTime.now();
//        上次面试时间+半年
            LocalDateTime plusDays = updatedTime.plusDays(183);
            if (now.isAfter(plusDays)){
                return false;
            }
        }
        return true;
    }

    @Override
    public void saveRecord(InterviewRecord interviewRecord) {
        interviewRecordMapper.insert(interviewRecord);
    }

    @Override
    public PageInfo<InterviewRecordVO> interviewRecordList(InterviewRecordBO interviewRecordBO) {
        PageHelper.startPage(interviewRecordBO.getPage(), interviewRecordBO.getPageSize());
        List<InterviewRecordVO> recordVOList = interviewRecordMapper.interviewRecordList(interviewRecordBO);
        PageInfo<InterviewRecordVO> voPageInfo = new PageInfo<>(recordVOList);
        return voPageInfo;
    }

    /**
     * 查询该面试记录详情
     * @param id
     * @return
     */
    @Override
    public InterviewRecord detail(String id) {
        InterviewRecord interviewRecord = interviewRecordMapper.selectById(id);
        return interviewRecord;
    }
}
